<!--
 * @name score
 * @description 组件描述
 * @author idouya
 * @email elegentfrog@163.com
 * @date 2025-07-03
 -->

<template>
  <div class="p-score common-bg common-layout">
    <page-title
      :discipline="gameInfo.discipline"
      :event="gameInfo.event"
      :match="gameInfo.match"
      :type="gameInfo.type"
      :eventName="gameInfo.eventName"
      :startTime="gameInfo.startTime"
      :showTime="true"
    ></page-title>
    <div class="content">
      <div class="content-top">
        <div class="line1">
          <div class="order">{{ atheleteInfo.Order }}</div>
          <div class="name">{{ atheleteInfo.AthleteName }}</div>
          <div class="club">{{ atheleteInfo.CountryName }}</div>
        </div>
        <div class="line1">
          <div class="order horseOrder">{{ atheleteInfo.HorseOrder }}</div>
          <div class="name horseName">{{ atheleteInfo.HorseName }}</div>
          <div class="line1-time">
            <div
              class="time posture"
              :style="
                posture.length > 8
                  ? posture.length > 15
                    ? 'font-size: 3.9rem'
                    : 'font-size: 4.1rem'
                  : ''
              "
            >
              {{ posture }}
            </div>
          </div>
        </div>
        <!-- <div class="line3">
          <div class="item" v-for="(item, index) in process" :key="index">
            <div>({{ item.order }})</div>
            <div>{{ item.name }}</div>
          </div>
        </div> -->
      </div>
      <div class="content-bottom"></div>
    </div>
  </div>
</template>

<script setup>
import useStore from '@/store'
import Storage from '@/assets/js/storage'
import Utils from '@/assets/js/utils'
import Config from '@/assets/js/config'
import { useMultiProcRequest } from '@/assets/js/useMultiProcRequest'

const { results, fetchForProcs } = useMultiProcRequest()

const gameInfo = ref({
  discipline: '马术',
  match: '',
  event: 'EVENTEAM',
  type: '出场信息',
  startTime: '13:01:29',
  matchType: '',
})

const atheleteInfo = ref({
  Order: 1,
  AthleteName: '杨舒涵',
  CountryName: '中国',
  HorseOrder: 201,
  horHorseNameseName: 'Joanna',
})

const { proxy } = getCurrentInstance()
const router = useRouter()
const route = useRoute()
const params = ref({})
const procName = ref([])
const commonStore = useStore.useCommonStore()
const showAction = ref(0)

onBeforeMount(() => {})
onMounted(() => {
  params.value = route.query
  procName.value = Config.procNameList[route.name]
  getData()
})

const posture = computed(() => {
  if (atheleteInfo.value?.Posture && showAction.value) {
    return atheleteInfo.value?.Posture
  }
  return ''
})

const getData = async () => {
  if (procName.value.length > 0) {
    await fetchForProcs(procName.value, {
      procName: procName.value[0],
      keyValues: params.value,
    })
  }
}

watchEffect(() => {
  if (results.value?.recordset) {
    gameInfo.value.event = results.value.recordset[0]?.EventCode
    gameInfo.value.match = results.value.recordset[0]?.MatchName
    gameInfo.value.eventName = results.value.recordset[0]?.EventName
    gameInfo.value.matchType = results.value.recordset[0]?.MatchType
    atheleteInfo.value = results.value.recordset[0]
  }
})

watch(
  () => route.query,
  (val) => {
    params.value = val
    getData()
  }
)

watch(
  () => commonStore.receivedActionMessages,
  (newVal, oldVal) => {
    if (newVal.length > 0) {
      const latestMsg = newVal[newVal.length - 1]
      const data = latestMsg?.data
      if (data?.showAction == 1) {
        // await getData()
        showAction.value = data?.showAction
      } else {
        showAction.value = false
      }
      if (data?.playAction == 'in') {
        showAction.value = 0
      }
    }
  },
  { deep: true, immediate: true }
)
</script>

<style scoped lang="scss">
@import '@/assets/scss/dressage/score4';
.posture {
  height: 100%;
  width: 100% !important;
}
</style>
